package com.woniu.service.impl;

import com.woniu.dao.CourseDao;


<<<<<<< .mine



=======

<<<<<<< .mine
import com.woniu.dao.CourseDao;
>>>>>>> .theirs
import com.woniu.dao.MapPathDao;

<<<<<<< .mine


=======
=======
import com.woniu.dao.MapPathDao;
>>>>>>> .theirs


import com.woniu.dao.MapPathDao;
import com.woniu.domain.Course;
import com.woniu.domain.MapPath;
import com.woniu.service.MapPathService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author: zcl  <br/>
 * Date: 2021/6/8:17:45  <br/>
 * Description:


<<<<<<< .mine
*/































=======

<<<<<<< .mine


import com.woniu.domain.Course;
import com.woniu.domain.MapPath;
import com.woniu.service.CourseService;
import com.woniu.service.MapPathService;
import org.assertj.core.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

=======














>>>>>>> .theirs
>>>>>>> .theirs
/**
 * @author: ljy  <br/>
 * Date: 2021/6/9:10:25  <br/>
 * Description: 学习路径业务实现类
 */
@Service
public class MapPathServiceImpl implements MapPathService {
    @Autowired(required = false)
    MapPathDao mapPathDao;

<<<<<<< .mine


=======


>>>>>>> .theirs

 @Autowired(required = false)

=======

    @Autowired(required = false)
<<<<<<< .mine


=======
>>>>>>> .theirs
    CourseDao courseDao;
>>>>>>> .theirs


<<<<<<< .mine
    CourseDao courseDao;

=======
<<<<<<< .mine

>>>>>>> .theirs


<<<<<<< .mine




=======
=======


>>>>>>> .theirs
>>>>>>> .theirs
    @Override
    @Transactional
    public int addMapPathAndMapPathExamConnect(MapPath mapPath) {

        return mapPathDao.addMapPath(mapPath)+mapPathDao.addMapPathExamConnect(mapPath);
    }

    @Override
    public MapPath findMapPathAndByName(String pathName) {
        return mapPathDao.findMapPathAndByName(pathName);
    }

    @Override
    public List<MapPath> findAllMapPath() {
        return mapPathDao.findAllMapPath();
    }

    @Override
    public MapPath findMapPathById(Integer id) {
        return mapPathDao.findMapPathById(id);
    }

    @Override
    public List<MapPath> findMapPathByIds(String[] ids) {
        return mapPathDao.findMapPathByIds(ids);
    }

    @Override
    @Transactional
    public int updateMapPathById(MapPath mapPath) {
        return mapPathDao.updateMapPathById(mapPath)+mapPathDao.updateMapPathExamConnectById(mapPath);
    }

<<<<<<< .mine





=======

<<<<<<< .mine



>>>>>>> .theirs
    @Override
    public List<MapPath> getMapPathByMapId(Integer mapId) {


<<<<<<< .mine
        List<MapPath> mapPathList = mapPathDao.getMapPathByMapId(mapId);















=======
=======


>>>>>>> .theirs

<<<<<<< .mine
 List<MapPath> mapPathList = mapPathDao.getMapPathByMapId(mapId);



=======

    @Override
    public List<MapPath> getMapPathByMapId(Integer mapId) {
        List<MapPath> mapPathList = mapPathDao.getMapPathByMapId(mapId);
>>>>>>> .theirs
>>>>>>> .theirs
        mapPathList.forEach(mapPath -> {
            String[] arrStr = mapPath.getRefContent().split(",");
            List<String> list=new ArrayList<String>(arrStr.length);
            Collections.addAll(list,arrStr);

            List<Course> courses = courseDao.batchQueryCourseId(list);
            mapPath.setCourses(courses);
        });
        return mapPathList;
    }

    @Override
    public List<MapPath> queryAllMapPath(){
        List<MapPath> mapPaths = mapPathDao.queryAllMapPath();
//        List<MapPath> list = new ArrayList<MapPath>();
        for (MapPath mapPath : mapPaths) {
            if(mapPath.getRefContent()!=null) {
                String[] arrStr = mapPath.getRefContent().split(",");
                List<String> strList = new ArrayList<String>(arrStr.length);
                Collections.addAll(strList, arrStr);
                List<Course> courses = courseDao.batchQueryCourseId(strList);
                System.out.println("-------------------------" + courses);
                mapPath.setCourses(courses);
            }
        }
        return mapPaths;
    }

    @Override
    public List<MapPath> cqueryAllMapPath(MapPath path) {
        List<MapPath> mapPaths = mapPathDao.cqueryAllMapPath(path);
//        List<MapPath> list = new ArrayList<MapPath>();
        for (MapPath mapPath : mapPaths) {
            if(mapPath.getRefContent()!=null){
                String[] arrStr = mapPath.getRefContent().split(",");
                List<String> strList=new ArrayList<String>(arrStr.length);
                Collections.addAll(strList,arrStr);
                List<Course> courses = courseDao.batchQueryCourseId(strList);
                System.out.println("-------------------------"+courses);
                mapPath.setCourses(courses);
            }
        }
        return mapPaths;
    }

    @Override
    public int delMapPath(Integer id) {
        return mapPathDao.delMapPath(id);
    }

}
